﻿using System;
using Common;

namespace FSM
{
    /// <summary>
    /// 有限状态机基类
    /// </summary>
    public abstract class FsmBase
    {
        private string m_Name;
        
        /// <summary>
        /// 初始化有限状态机基类的新实例
        /// </summary>
        public FsmBase() => this.m_Name = string.Empty;

        /// <summary>
        /// 获取有限状态机的名称
        /// </summary>
        public string Name
        {
            get => this.m_Name;
            protected set => this.m_Name = value;
        }
        /// <summary>
        /// 获取有限状态机的全名称
        /// </summary>
        public string FullName => new TypeNamePair(this.OwnerType, this.m_Name).ToString();

        /// <summary>
        /// 获取有限状态机的持有者类型
        /// </summary>
        public abstract Type OwnerType { get; }

        /// <summary>
        /// 获取有限状态机的状态数量
        /// </summary>
        public abstract int FsmStateCount { get; }

        /// <summary>
        /// 获取有限状态机是否正在运行
        /// </summary>
        public abstract bool IsRunning { get; }
        
        /// <summary>
        /// 获取有限状态机是否被销毁
        /// </summary>
        public abstract bool IsDestroyed { get; }

        /// <summary>
        /// 获取当前状态机状态的名称
        /// </summary>
        public abstract string CurrentStateName { get; }

        /// <summary>
        /// 获取当前有限状态机持续时间
        /// </summary>
        public abstract float CurrentStateDurationTime { get; }

        /// <summary>
        /// 有限状态机轮询
        /// </summary>
        /// <param name="elapseSeconds"></param>
        /// <param name="realElapseSeconds"></param>
        internal abstract void Update(float elapseSeconds, float realElapseSeconds);
        
        /// <summary>
        /// 关闭并清理有限状态机
        /// </summary>
        internal abstract void Shutdown();
    }
}